// 引入koa-router
const Router = require('koa2-router');
const router = new Router();
const sql = require('../../config/config');
// 引入jsonwebtoken模块
const jwt = require("jsonwebtoken");
const SECRET = "hello";
//个人资料
router.get('/personalData',async ctx=>{
    //获取token
    const token = ctx.request.headers.authorization;
    //解密token
    let decoded = jwt.verify(token, SECRET);
    //获取前端传的值
    // console.log(ctx.query);
    const id = decoded.ID;
    if (ctx.query.code==='200'){
        const {phone,nickname,sex,pic,birthdayYear,birthdayMonth,birthdayDay,email,province,city,district,occupation} = ctx.query
        await sql('update user set mobilePhone=?,nickname=?,gender=?,headPortrait=?,birthdayYear=?,birthdayMonth=?,birthdayDay=?,email=?,province=?,city=?,district=?,occupation=? where id=?',[phone,nickname,sex,pic,birthdayYear,birthdayMonth,birthdayDay,email,province,city,district,occupation,id])
    }
    //获取当前登入的用户的表
    const myOrder = await sql(`select * from user where id = ${id}`);
    // console.log(myOrder);
    //发送
    ctx.body = myOrder;
})

module.exports = router;
